package com.zyk.leetcode;

/**
 * @author zhangsan
 * @date 2021/4/4 19:26
 */
public class J28 {

    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x) {
            val = x;
        }
    }


    public static boolean isSymmetric(TreeNode root) {
        if(root == null) {
            return true;
        }
        return recur(root.left, root.right);
    }

    /** 左树的左边和右树的右边, 左树的右边和右树的左边 比较 */
    private static boolean recur(TreeNode left, TreeNode right) {
        if(left == null && right == null) {
            return true;
        }
        if(left == null || right == null || left.val != right.val) {
            return false;
        }
        return recur(left.left, right.right) && recur(left.right, right.left);
    }


    // for test
    public static void main(String[] args) {

    }

}
